<HTML>
  <HEAD>
    <TITLE>threadpool Documentation</TITLE>
    <LINK HREF="threadpool.css" REL="stylesheet" TYPE="text/css">
  </HEAD>
  <BODY BGCOLOR="#FFFFFF">

    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>

          <TD ALIGN="LEFT">
            <B>threadpool</B>
          </TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="../index.html">Overview</A> |
            <A CLASS="qindex" HREF="../reference/annotated.html">Reference</A> |
            <A CLASS="qindex" HREF="../tutorial/intro.html">Tutorial</A> |
            <A CLASS="qindex" HREF="../examples/intro.html">Examples</A> |
            <A CLASS="qindex" HREF="../design/intro.html">Design</A>
          </TD>

        </TR>
      </TABLE>
    </DIV>
    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>
          <TD ALIGN="LEFT">
            <B>Reference</B>
          </TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="annotated.html">Class List</A> |
            <A CLASS="qindex" HREF="functions.html">Member Functions</A> |
            <A CLASS="qindex" HREF="namespacemembers.html">Typedefs</A> |
            <A CLASS="qindex" HREF="files.html">File List</A>
          </TD>
        </TR>
      </TABLE>
    </DIV>
<!-- Generated by Doxygen 1.4.6-NO -->
<h1>threadpool/size_policies.hpp</h1><a href="a00033.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00018"></a>00018 <span class="preprocessor">#ifndef THREADPOOL_SIZE_POLICIES_HPP_INCLUDED</span>
<a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor">#define THREADPOOL_SIZE_POLICIES_HPP_INCLUDED</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 
<a name="l00024"></a>00024 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>threadpool
<a name="l00025"></a>00025 {
<a name="l00026"></a>00026 
<a name="l00031"></a>00031   <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Pool&gt;
<a name="l00032"></a><a class="code" href="a00015.html">00032</a>   <span class="keyword">struct </span><a class="code" href="a00015.html">empty_controller</a>
<a name="l00033"></a>00033   {
<a name="l00034"></a><a class="code" href="a00015.html#73f5f4ee18d235dbe1de9ac1ca13e7d3">00034</a>     <a class="code" href="a00015.html#73f5f4ee18d235dbe1de9ac1ca13e7d3">empty_controller</a>(<span class="keyword">typename</span> Pool::size_policy_type&amp;, shared_ptr&lt;Pool&gt;) {}
<a name="l00035"></a>00035   };
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 
<a name="l00042"></a>00042   <span class="keyword">template</span>&lt; <span class="keyword">typename</span> Pool &gt;
<a name="l00043"></a><a class="code" href="a00022.html">00043</a>   <span class="keyword">class </span><a class="code" href="a00022.html">resize_controller</a>
<a name="l00044"></a>00044   {
<a name="l00045"></a>00045     <span class="keyword">typedef</span> <span class="keyword">typename</span> Pool::size_policy_type size_policy_type;
<a name="l00046"></a>00046     reference_wrapper&lt;size_policy_type&gt; m_policy;
<a name="l00047"></a>00047     shared_ptr&lt;Pool&gt; m_pool;                           
<a name="l00048"></a>00048 
<a name="l00049"></a>00049   <span class="keyword">public</span>:
<a name="l00050"></a><a class="code" href="a00022.html#3a1abded6a9bc292d679f322bd41e008">00050</a>     <a class="code" href="a00022.html#3a1abded6a9bc292d679f322bd41e008">resize_controller</a>(size_policy_type&amp; policy, shared_ptr&lt;Pool&gt; <a class="code" href="a00024.html">pool</a>)
<a name="l00051"></a>00051       : m_policy(policy)
<a name="l00052"></a>00052       , m_pool(pool)
<a name="l00053"></a>00053     {
<a name="l00054"></a>00054     }
<a name="l00055"></a>00055 
<a name="l00056"></a><a class="code" href="a00022.html#40824a6345c2d03b4ff21f125186279e">00056</a>     <span class="keywordtype">bool</span> <a class="code" href="a00022.html#40824a6345c2d03b4ff21f125186279e">resize</a>(size_t worker_count)
<a name="l00057"></a>00057     {
<a name="l00058"></a>00058       <span class="keywordflow">return</span> m_policy.get().resize(worker_count);
<a name="l00059"></a>00059     }
<a name="l00060"></a>00060   };
<a name="l00061"></a>00061 
<a name="l00062"></a>00062 
<a name="l00067"></a>00067   <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Pool&gt;
<a name="l00068"></a><a class="code" href="a00023.html">00068</a>   <span class="keyword">class </span><a class="code" href="a00023.html">static_size</a>
<a name="l00069"></a>00069   {
<a name="l00070"></a>00070     reference_wrapper&lt;Pool volatile&gt; m_pool;
<a name="l00071"></a>00071 
<a name="l00072"></a>00072   <span class="keyword">public</span>:
<a name="l00073"></a><a class="code" href="a00023.html#ff83c25faed61462b846115ea543608d">00073</a>     <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="a00023.html#ff83c25faed61462b846115ea543608d">init</a>(Pool&amp; <a class="code" href="a00024.html">pool</a>, size_t <span class="keyword">const</span> worker_count)
<a name="l00074"></a>00074     {
<a name="l00075"></a>00075       pool.resize(worker_count);
<a name="l00076"></a>00076     }
<a name="l00077"></a>00077 
<a name="l00078"></a><a class="code" href="a00023.html#a30e8966810a898fe6cf35d8668fd2f6">00078</a>     <a class="code" href="a00023.html#a30e8966810a898fe6cf35d8668fd2f6">static_size</a>(Pool <span class="keyword">volatile</span> &amp; <a class="code" href="a00024.html">pool</a>)
<a name="l00079"></a>00079       : m_pool(pool)
<a name="l00080"></a>00080     {}
<a name="l00081"></a>00081 
<a name="l00082"></a><a class="code" href="a00023.html#c2bbeb9b1c9afd79d5336eb88c53d79d">00082</a>     <span class="keywordtype">bool</span> <a class="code" href="a00023.html#c2bbeb9b1c9afd79d5336eb88c53d79d">resize</a>(size_t <span class="keyword">const</span> worker_count)
<a name="l00083"></a>00083     {
<a name="l00084"></a>00084       <span class="keywordflow">return</span> m_pool.get().resize(worker_count);
<a name="l00085"></a>00085     }
<a name="l00086"></a>00086 
<a name="l00087"></a><a class="code" href="a00023.html#9524a72cbd4f8fbcd6c2b9a3115865d3">00087</a>     <span class="keywordtype">void</span> <a class="code" href="a00023.html#9524a72cbd4f8fbcd6c2b9a3115865d3">worker_died_unexpectedly</a>(size_t <span class="keyword">const</span> new_worker_count)
<a name="l00088"></a>00088     {
<a name="l00089"></a>00089       m_pool.get().resize(new_worker_count + 1);
<a name="l00090"></a>00090     }
<a name="l00091"></a>00091 
<a name="l00092"></a>00092     <span class="comment">// TODO this functions are not called yet</span>
<a name="l00093"></a><a class="code" href="a00023.html#21507d78c2dee1d94809e44fc969c564">00093</a>     <span class="keywordtype">void</span> <a class="code" href="a00023.html#21507d78c2dee1d94809e44fc969c564">task_scheduled</a>() {}
<a name="l00094"></a><a class="code" href="a00023.html#101b2c4b2ca972bf4045c2dfb81a026d">00094</a>     <span class="keywordtype">void</span> <a class="code" href="a00023.html#101b2c4b2ca972bf4045c2dfb81a026d">task_finished</a>() {}
<a name="l00095"></a>00095   };
<a name="l00096"></a>00096 
<a name="l00097"></a>00097 } } <span class="comment">// namespace boost::threadpool</span>
<a name="l00098"></a>00098 
<a name="l00099"></a>00099 <span class="preprocessor">#endif // THREADPOOL_SIZE_POLICIES_HPP_INCLUDED</span>
</pre></div>    <BR>
    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>
		  <TD CLASS="tiny" ALIGN="LEFT">Copyright &copy 2005-2007 Philipp Henkel</TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="../index.html">Overview</A> |
            <A CLASS="qindex" HREF="../reference/annotated.html">Reference</A> |
            <A CLASS="qindex" HREF="../tutorial/intro.html">Tutorial</A> |
            <A CLASS="qindex" HREF="../examples/intro.html">Examples</A> |
            <A CLASS="qindex" HREF="../design/intro.html">Design</A>
          </TD>
        </TR>       
      </TABLE>
    </DIV>  
  </BODY>
</HTML>
